package com.zego.zegowawaji_server.manager;

import android.content.Context;
import android.text.TextUtils;

import com.zego.base.utils.DeviceIdUtil;
import com.zego.base.utils.PrefUtil;

/**
 * 直播推流管理类
 */
public class LiveMgr {
    static private LiveMgr sInstance;

    static public LiveMgr getInstance() {
        if (sInstance == null) {
            synchronized (LiveMgr.class) {
                if (sInstance == null) {
                    try {
                        sInstance = new LiveMgr();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        return sInstance;
    }

    // ==================================================================================
    static final public String ROOM_ID_PREFIX = "XS_WWJ";            // 房间号：头部拼接
    static final public String STREAM_ID_PREFIX = "XS_TEAM";   // 推流号：头部拼接

    /**
     * 创建房间ID，双路推流ID
     */
    public void initRoomAndStreamInfo(Context context) {
        PrefUtil prefUtil = PrefUtil.getInstance();
        if (TextUtils.isEmpty(prefUtil.getRoomId())
                || TextUtils.isEmpty(prefUtil.getStreamId())
                || TextUtils.isEmpty(prefUtil.getStreamId2())) {
            String deviceId = DeviceIdUtil.generateDeviceId(context);

            String roomId = String.format("%s_%s", ROOM_ID_PREFIX, deviceId);
            PrefUtil.getInstance().setRoomId(roomId);

            String streamId = String.format("%s_%s", STREAM_ID_PREFIX, deviceId);
            PrefUtil.getInstance().setStreamId(streamId);

            String streamId2 = String.format("%s_%s_2", STREAM_ID_PREFIX, deviceId);
            PrefUtil.getInstance().setStreamId2(streamId2);
        }
    }
}
